#ifndef BANK_BANKSYSTEM_HH
#define BANK_BANKSYSTEM_HH

#include <string>
#include <vector>
#include <memory>
#include <map>
#include <set>

#include "Customer.hh"
#include "Account.hh"
#include "Transaction.hh"
#include "ReportGenerator.hh"
#include "AuthManager.hh"
#include "DataManager.hh"

class BankSystem {
private:
    std::vector<std::shared_ptr<Customer>> customers;
    std::vector<std::shared_ptr<Account>> accounts;
    std::vector<Transaction> transactions;
    std::set<std::string> existingAccountIds;  // 用于确保账号唯一性
    
    AuthManager& authManager;
    ReportGenerator reportGenerator;
    DataManager dataManager;

public:
    BankSystem(AuthManager& auth);
    ~BankSystem();

    // 数据持久化方法
    bool saveData();
    bool loadData();

    // 客户管理
    bool registerCustomer(const std::string& name);
    bool registerCustomer(const std::string& name, const std::string& password);
    std::shared_ptr<Customer> findCustomerByName(const std::string& name) const;
    const std::vector<std::shared_ptr<Customer>>& getAllCustomers() const;

    // 删除客户和账户
    bool deleteCustomer(const std::string& customerName, const std::string& password);
    bool deleteAccount(const std::string& accountId, const std::string& customerName, const std::string& password);
    bool adminDeleteAccount(const std::string& accountId);

    // 账户管理
    std::shared_ptr<Account> findAccountById(const std::string& accountId) const;
    const std::vector<std::shared_ptr<Account>>& getAllAccounts() const;
    void displayAllAccounts() const;

    // 存款、取款、转账操作
    bool deposit(const std::string& accountId, double amount, const std::string& note = "");
    bool deposit(const std::string& accountId, double amount, Currency currency, const std::string& note = "");
    
    bool withdraw(const std::string& accountId, double amount, const std::string& note = "");
    bool withdraw(const std::string& accountId, double amount, Currency currency, const std::string& note = "");
    
    bool transfer(const std::string& sourceAccountId, const std::string& destinationAccountId, 
                double amount, const std::string& note = "");
    bool transfer(const std::string& sourceAccountId, const std::string& destinationAccountId, 
                double amount, Currency currency, const std::string& note = "");

    // 交易记录
    void addTransaction(const Transaction& transaction);
    const std::vector<Transaction>& getAllTransactions() const;
    std::vector<Transaction> getTransactionsByAccountId(const std::string& accountId) const;
    std::vector<Transaction> getTransactionsByCustomerName(const std::string& customerName) const;

    // 报告生成
    bool generateGlobalTransactionReport() const;
    bool generateCustomerReport(const std::string& customerName) const;
    bool generateAccountReport(const std::string& accountId) const;
    bool generateQuarterlyReport(int year, int quarter) const;

private:
    // 辅助方法：创建并获取一个唯一的账号
    std::string generateUniqueAccountId(const std::string& accountType);
    
    // 辅助方法：为新客户创建储蓄账户和支票账户
    void createAccountsForCustomer(std::shared_ptr<Customer> customer);
};

#endif // BANK_BANKSYSTEM_HH 